/**
 * 定义分钟数据模块
 */
(function(window, angular, undefined){
	var module = angular.module('water.apps.voc.reportHistory.reportMinDataManager', ['water.apps.common.report.reportBase','water.entity.monitorData']);
	
	module.controller('reportMinDataManagerController',function($rootScope,$scope,$controller,$wasteGasMonitorDataService){

		var control = $controller("commonReportAuditController",{$scope:$scope});
		
		$scope.dataAPIName = "minuteListGetter";
		$scope.dataAuditAPIName = "minuteAuditListGetter";
		$scope.dataExportAPIName = "exportMinExcel";
		/**
		 * 数据项
		 */
		$scope.dataType=[];
		/**
		 * 数据主键集合
		 */
		$scope.keys = [];
		/**
		 * 数据状态
		 */
		$scope.dataState="0";
		
		/**
		 * 数据状态切换按钮
		 */
		$scope.onDataStateChange = function(){
			var queryObject = $scope.getQueryObject();
			if($scope.dataState==1)  //审核后数据
			{
				$scope.getAuditReport(queryObject);
			}else{ 	 	 //原始数据
				$scope.getReport(queryObject);
			}

		}
		
		/**
		 * 监听左侧列表选择
		 */
		$scope.oNdataPramChanged = $scope.$on('dataPramChanged', function(event, station) {
			$scope.onStationSelectedBeforeQuery(station);
			pollFreshLag=true;
	    });
		
		/**
		 * 站点改变后，更新构建报表的参数，比如表头，数据项等
		 */
		$scope.onStationSelectedBeforeQuery = function(station){
			$scope.selectedModel = station;
			$scope.parmList = station.parmToCheckList;
			var parmListNew=[];
			$scope.dataType=[];
			for(var i=0;i<$scope.parmList.length;i++){
				var parm=$scope.parmList[i];
				if(parm.name=="01"||parm.name=="02"||parm.name=="03"||parm.name=="04"||parm.name=="06"||parm.name=="08") {
					parm.colspan=2;
					$scope.dataType.push("实测值");
					$scope.dataType.push("折算值");
				}
				else{
					parm.colspan=1;
					$scope.dataType.push("实测值");
				}
				parmListNew.push(parm);
			}
			$scope.parmList= parmListNew;
			
			$scope.keys = [];
			for(var i=0;i<$scope.parmList.length;i++){
				var obj = $scope.parmList[i];
				if(obj.name=="01"||obj.name=="02"||obj.name=="03"||obj.name=="04"||obj.name=="06"||obj.name=="08") {
					$scope.keys.push("AVG_"+obj.name);
					$scope.keys.push("ZS_AVG_"+obj.name);
				}
				else{
					$scope.keys.push("AVG_"+obj.name);
				}
			}
			$scope.onDataStateChange();
		};
		/**
		 * 获取查询参数
		 * forExcel 是否用于导出
		 */
		$scope.getQueryObject = function(forExcel){

			var startTime =$scope.queryDate + " " + $scope.startHour + ":00:00";
			var endTime = $scope.queryDate + " " + $scope.endHour + ":55:00";
			var parmsStr = $scope.selectedModel.parmToChecksStr;
			var queryObject = {
					"MN":$scope.selectedModel.MN,
					"PARMS":parmsStr,
					"START":startTime,
					"END":endTime,
					"EXPORT":forExcel
				};
			return queryObject;
		}
	});
}(window, angular));	